import {Component, Input, OnInit} from '@angular/core';
import {FileInfo, FileType} from "@shared/models/FileInfo";
import {BBYUtils} from "@shared/utils/BBYUtils";
import {api} from "@core/service/config/api";
import {Router} from "@angular/router";

@Component({
  selector: 'bby-file-info',
  templateUrl: './file-info.component.html',
  styleUrls: ['./file-info.component.scss']
})
export class FileInfoComponent implements OnInit {

  @Input()
  checkedFiles: FileInfo[]=[];
  @Input()
  rootUrl = 'myDisk'
  @Input()
  path='';
  file=new FileInfo();
  no_permission_url='assets/img/no-permission.png'
  constructor(
    private router:Router
  ) {
  }
  ngOnInit(): void {
  }

  setFile(file:FileInfo,){

  }
  getSuffix(name: string) {
    return BBYUtils.getFileSuffix(name)
  }

  getImgUrl() {
    if (this.checkedFiles.length==1){
      let file = this.checkedFiles[0]
      if (file.type==FileType.IMG){
        return file.directId? `${api.imgView}/${file.id}?directId=${file.directId}` : this.no_permission_url
      } if (file.type==FileType.VIDEO){
        return file.directId? `${api.imgView}/${file.id}?directId=${file.directId}` : this.no_permission_url
      }
        return BBYUtils.getTypeImg(file)
    }
    return 'assets/img/folder.png'
  }

  getTypeImg(file: FileInfo) {
    return BBYUtils.getTypeImg(file)
  }

  openPath(path:string=this.checkedFiles[0].owner) {
    // this.router.navigate([this.rootUrl],{queryParams:{id:this.checkedFiles[0].id}})
    this.router.navigate([`${this.rootUrl}/${path}`])
  }

  getUserName(id: any) {
    return BBYUtils.userIdNameMap.get(id)||id
  }
}
